﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization.Json;
using System.ComponentModel.DataAnnotations;
using System.IO;
namespace RMS.Common
{
    public static class SerializationManager
    {
        public static string ModelToJson<T>(this T model)
        {
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(model.GetType());

            using (MemoryStream ms = new MemoryStream())
            {
                serializer.WriteObject(ms, model);
                StringBuilder sb = new StringBuilder();
                sb.Append(Encoding.UTF8.GetString(ms.ToArray()));
                return sb.ToString();
            }

        }
    }
}
